package com.mxm.mirai.web;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresRoles;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;

@RestController
@Api(value = "System 获取类")
public class SystemInfoWeb {
    private static Map<String,Object> datastate;

    @GetMapping("/getInfo")
    @RequiresRoles(logical = Logical.OR, value = {"user"})
    @ApiOperation(value = "系统配置信息", notes = "系统配置信息--拦截")
    public Map getInfo(){
        datastate = new HashMap();
        InetAddress addr = null;
        String ip = null;
        try {
            addr = InetAddress.getLocalHost();
            ip = addr.getHostAddress();
        } catch (UnknownHostException e) {
            ip = "获取失败";
        }
        Properties props = System.getProperties();
        Map<String, String> map = System.getenv();
        datastate.put("username",map.get("USERNAME"));// 获取用户名
        datastate.put("computername",map.get("COMPUTERNAME"));// 获取计算机名
        datastate.put("os_name",props.getProperty("os.name"));//系统名称
        datastate.put("os_arch",props.getProperty("os.arch"));//系统构架
        datastate.put("os_version",props.getProperty("os.version"));//系统版本
        datastate.put("os_ip",ip);//本地ip
        datastate.put("java_version",props.getProperty("java.version"));//Java版本
        return datastate;
    }
}
